package com.zw.service;

import com.zw.vo.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * 自定义权限校验（权限校验方式1）
 */
@Component("ss")
public class PermissionService {

    /**
     * 校验是否存在某权限
     * @return
     */
    public boolean hasPermi(String permission){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser)authentication.getPrincipal();
        Set<String> permissions = loginUser.getPermissions();
        if (permissions.contains(permission)){
            return true;
        }
        return false;
    }
}
